$(function() {	
	//初始化BTN
	initBtnUI();
	
	//初始化窗口
	initWindowUI();
	
	//初始化数据表
	initDataGridUI();
	
});

//初始化BTN
function initBtnUI(){
	//流程挂接BTN
	$('#mountWorkflowProcessBtn').linkbutton({plain:true,iconCls:'icon-mount'});
	$('#cancelWorkflowProcessBtn').linkbutton({plain:true,iconCls:'icon-unmount'});
	$('#workflowProcessEventsBtn').linkbutton({plain:true,iconCls:'icon-process'});
	$('#workflowTasksBtn').linkbutton({plain:true,iconCls:'icon-task'});
	$('#closeWorkflowProcessFunMountBtn').linkbutton({plain:true,iconCls:'icon-close'});
}


//初始化数据表
function initDataGridUI(){
	//初始化数据表格
	$('#workflowProcessFunMountDataGrid').datagrid({
		url:'workflowProcessFunMountAjax!loadWorkflowProcessFunMountData',
		idField:'id',
		sortName: 'id',
		sortOrder: 'desc',
		border:false,
		nowrap: false,
		striped: true,
		remoteSort:false,
		rownumbers:true,
		pagination:true,
		collapsible:true,
		singleSelect:true,
		toolbar:'#workflowProcessFunMountToolBar',
		columns:[[
			{field:'processName',title:'流程名称',width:200},
			{field:'processKey',title:'流程键值',width:200},
			{field:'modelName',title:'实体名称',width:200},
			{field:'modelIdName',title:'实体主键',width:80},
			{field:'mountStatus',title:'挂接状态',width:80},
			{field:'version',title:'流程版本',width:80}
		]]
	});

	//分页
	var wpfmdgPager = $('#workflowProcessFunMountDataGrid').datagrid('getPager');
	$(wpfmdgPager).pagination({
		pageSize: 15,
		pageList: [15, 30, 50, 100],
		beforePageText: '第',
		afterPageText: '页    共 {pages} 页',
		displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
		onSelectPage:function(pageNumber, pageSize){
			$('#workflowProcessFunMountDataGrid').datagrid('options').url = 'workflowProcessFunMountAjax!loadWorkflowProcessFunMountData?pageNo=' + pageNumber + '&pageSize='+ pageSize;
			$('#workflowProcessFunMountDataGrid').datagrid('reload', pageNumber);
		}
	});
}

//初始化窗口
function initWindowUI(){
	
}

//流程挂接
function mountProcessFun(){
	var row = $('#workflowProcessFunMountDataGrid').datagrid('getSelected');
	if(ROW_IS_NOT_NULL(row)){
		$.post('workflowProcessFunMountAjax!mountWorkflowProcessFun', {id:row.id},
				function(data){
					$.messager.alert('提示','流程挂接成功!');
					$('#workflowProcessFunMountDataGrid').datagrid('reload');
			}, 'json').error(function() {
				$.messager.alert("提示", "流程挂接失败!");
			});
	}
	
}

//取消流程挂接
function unMountProcessFun(){
	var row = $('#workflowProcessFunMountDataGrid').datagrid('getSelected');
	if(ROW_IS_NOT_NULL(row)){
		$.post('workflowProcessFunMountAjax!unMountWorkflowProcessFun', {id:row.id},
				function(data){
					$.messager.alert('提示','流程取消挂接成功!');
					$('#workflowProcessFunMountDataGrid').datagrid('reload');
			}, 'json').error(function() {
				$.messager.alert("提示", "流程取消挂接失败!");
			});
	}
	
}


